package ua.kharkov.knure.pereverziev.diploma.db.entity;

import java.io.Serializable;
import java.sql.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity(name = "flights")
public class Flight extends HasId implements Serializable {

	private static final long serialVersionUID = -1L;

	public Flight() {
	}

	public Flight(final Long flightNumber) {
		this.id = flightNumber;
	}

	public Flight(final Schedule schedule, final Date flightDate,
			final Float price) {
		this.schedule = schedule;
		this.flightDate = flightDate;
		this.price = price;
	}

	@Id
	@Column(name = "flight_id")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@ManyToOne
	@JoinColumn(name = "schedule_id")
	private Schedule schedule;

	@Column(name = "flight_date")
	private Date flightDate;

	private Float price;

	public String getDescription() {
		return "#" + id + " " + flightDate + " "
				+ schedule.getShortDescription();
	}

	// -------------- Getters and setters -------------

	@Override
	public String toString() {
		return "Flight [id=" + id + ", schedule=" + schedule + ", flightDate="
				+ flightDate + "]\n";
	}

	@Override
	public Long getId() {
		return id;
	}

	@Override
	public void setId(final Long id) {
		this.id = id;
	}

	public Schedule getSchedule() {
		return schedule;
	}

	public void setSchedule(final Schedule schedule) {
		this.schedule = schedule;
	}

	public Date getFlightDate() {
		return flightDate;
	}

	public void setFlightDate(final Date flightDate) {
		this.flightDate = flightDate;
	}

	public Float getPrice() {
		return price;
	}

	public void setPrice(final Float price) {
		this.price = price;
	}

}